package IteratorAndComposite.IteratorInterfacesImpl;

import IteratorAndComposite.IteratorInterfaces.Iterator;
import IteratorAndComposite.entry.MenuItem;

/**
 * @Author: pengzx
 * @Description:
 * @Date: 16:25 2017/9/19
 * @Modified by: 1.0
 */
public class DinerMenuIterator implements Iterator {
    MenuItem[] menuItems;
    int position = 0;//记录当前数组遍历的位置


    public DinerMenuIterator(MenuItem[] menuItems)
    {
        this.menuItems = menuItems;
    }
    @Override
    public boolean hasNext()
    {
        if (menuItems.length<=position|| menuItems[position] == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Object next()
    {
        MenuItem menuItem = menuItems[position];
        position++;
        return menuItem;
    }


}
